//The following example creates a file:

#include <stdio.h>
#include <fcntl.h>

main() {
  char fn[]="creat.file", text[]="This is a test";
  int fd, rc;

  if ((fd = creat(fn, S_IRUSR | S_IWUSR)) < 0)
    perror("creat() error");
  else {
    if (-1==(rc=write(fd, text, strlen(text))))
      perror("write() error");
    if (close(fd) != 0)
      perror("close() error");
    if (unlink(fn)!= 0)
      perror("unlink() error");
  }
}
